package 摆动序列;

class Solution {
    public int wiggleMaxLength(int[] nums) {
        int n = nums.length;
        int l = 0, r = 0, ret = 0;
        for (int i = 0; i < n - 1; i++) {
            r = nums[i + 1] - nums[i];
            if (r == 0) {
                continue;
            }
            if (l * r <= 0) {
                ret++;
            }
            l = r;
        }
        return ret + 1;
    }
}